local fangquan = fk.CreateSkill {

  name = "joyex__fangquan",

  tags = {  },

}



fangquan:addEffect(fk.EventPhaseChanging, {
  name = "joyex__fangquan",
  anim_type = "support",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(fangquan.name) and player == target and data.to == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    player:skip(Player.Play)
    return true
  end,
})

fangquan:addEffect(fk.EventPhaseStart, {
  name = "#joyex__fangquan_delay",
  events = {fk.EventPhaseStart},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player.phase == Player.Discard and player:usedSkillTimes(fangquan.name, Player.HistoryTurn) > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, fangquan.name, "support")
    local tar, cards = {},{}
    tar = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper),1,1, "放权：选择一名其他角色，然后交给其任意张牌并令其获得一个额外的回合。","joyex__fangquan",true)
    if #tar > 0  then
      local to =  room:getPlayerById(tar[1])
      cards = room:askForCard(player,1,#player:getCardIds("he"),true,"joyex__fangquan",true,".","你可以交给其任意张牌。")
      if #cards > 0 then
        room:moveCardTo(cards, Card.PlayerHand,to,fk.ReasonGive,"joyex__fangquan", nil,false, player.id)
      end
      if not to.dead then
        to:gainAnExtraTurn()
      end
    end
  end,
})

return fangquan